package org.cyhz.main;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.cyhz.utils.Log;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;

@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DiscardMessageListener implements MessageListener {

    private String queueName;

    public String getQueueName() {
        return queueName;
    }

    public void setQueueName(String queueName) {
        this.queueName = queueName;
    }

    @Override
    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            try {
                TextMessage text = (TextMessage) message;
                String msg = text.getText();
                Log.info("queue " + queueName + " receive " + msg);
            } catch (JMSException e) {
                Log.error(queueName + " listener error" + e.getMessage(), e);
            } catch (Exception e) {
                Log.error(queueName + " error" + e.getMessage(), e);
            }
        }
    }
}
